package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.pojo.AddressBook;
import com.sky.pojo.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 分类管理
 * @Author lyh
 * @Date 2024-09-20
 */
@RestController
@Slf4j
@RequestMapping("/admin/category")
@Api(tags = "分类管理")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 根据条件分类查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分类管理分页查询")
    public Result<PageResult> pageQuery(CategoryPageQueryDTO dto){
     PageResult pageResult=categoryService.pageQuery(dto);
     return Result.success(pageResult);
    }

    /**
     * 新增分类
     * @param dto
     * @return
     */
    @PostMapping
    @ApiOperation("新增分类")
    public Result<String> save(@RequestBody CategoryDTO dto){
        categoryService.save(dto);
        return Result.success();
    }

    /**
     * 删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除分类")
    public Result<String> delete(Integer id){
        categoryService.delete(id);
        return Result.success();
    }

    /**
     * 修改分类
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("修改分类")
    public Result<String> update(@RequestBody CategoryDTO dto){
        categoryService.update(dto);
        return Result.success();
    }

    /**
     * 启用禁用分类
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result<String> updateStatus(@PathVariable Integer status,Long id){
        categoryService.updateStatus(status,id);
        return Result.success();
    }
    /**
     * 根据类型查询分类
     * @param type =1  菜品分类    type= 2  套餐分类
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type){
      List<Category> list=categoryService.list(type);
      return Result.success(list);
    }
}
